package comparisionAndResults;

import java.util.HashMap;
import java.util.Iterator;

import ModelRepresentations.NodesAndValues;

/**
 * The datastructure used to hold the result from the graph-edit distance algorithm implemented in ModelComparer.java
 * @author Mattis
 *
 */
public class GraphEditDistanceData {
	private float IADNodes = 0.0f; // inserted and deleted nodes
	private float IADEdges = 0.0f; // inserted and deleted edges
	private float SubNodes = 0.0f; // substituted nodes
	private float mappedNodesTotal = 0.0f; // result of summing 1 - the syntactic-similarity for each mapped node pair
	private HashMap<String, NodesAndValues> mapping;
	/**
	 * creates an instance of the GraphEditDistanceData class
	 * @param iADNodes the number of inserted and deleted nodes
	 * @param iADEdges the number of inserted and deleted edges
	 * @param subNodes the number of substituted nodes
	 */
	public GraphEditDistanceData(float iADNodes, float iADEdges, float subNodes) {
		IADNodes = iADNodes;
		IADEdges = iADEdges;
		SubNodes = subNodes;
	}
	
	/**
	 * creates an instance of the GraphEditDistanceData class
	 * @param iADNodes the number of inserted and deleted nodes
	 * @param iADEdges the number of inserted and deleted edges
	 * @param subNodes the number of substituted nodes
	 * @param mappedNodesTotal the result of summing 1 - the syntactic-similarity for each mapped node pair
	 */
	public GraphEditDistanceData(float iADNodes, float iADEdges,
			float subNodes, float mappedNodesTotal) {
		super();
		IADNodes = iADNodes;
		IADEdges = iADEdges;
		SubNodes = subNodes;
		this.mappedNodesTotal = mappedNodesTotal;
	}
	
	

	public GraphEditDistanceData(float iADNodes, float iADEdges,
			float subNodes, float mappedNodesTotal,
			HashMap<String, NodesAndValues> mapping) {
		IADNodes = iADNodes;
		IADEdges = iADEdges;
		SubNodes = subNodes;
		this.mappedNodesTotal = mappedNodesTotal;
		this.mapping = mapping;
	}

	/**
	 * gets the number of inserted and deleted nodes
	 * @return the number of inserted and deleted nodes
	 */
	public float getIADNodes() {
		return IADNodes;
	}
	
	/**
	 * sets the number of inserted and deleted nodes
	 * @param iADNodes is the number of inserted and deleted nodes
	 */
	public void setIADNodes(float iADNodes) {
		IADNodes = iADNodes;
	}
	
	/**
	 * gets the number of inserted and deleted edges
	 * @return the number of inserted and deleted edges
	 */
	public float getIADEdges() {
		return IADEdges;
	}
	
	/**
	 * sets the number of inserted and deleted edges
	 * @param iADEdges the number of inserted and deleted edges
	 */
	public void setIADEdges(float iADEdges) {
		IADEdges = iADEdges;
	}
	
	/**
	 * gets the number of substituted nodes
	 * @return the number of substituted nodes
	 */
	public float getSubNodes() {
		return SubNodes;
	}
	
	/**
	 * sets the number of substituted nodes
	 * @param subNodes the number of substituted nodes
	 */
	public void setSubNodes(float subNodes) {
		SubNodes = subNodes;
	}
	
	/**
	 * gets the result of summing 1 - the syntactic-similarity for each mapped node pair
	 * @return the mapped nodes total
	 */
	public float getMappedNodesTotal() {
		return mappedNodesTotal;
	}
	
	/**
	 * sets the result of summing 1 - the syntactic-similarity for each mapped node pair
	 * @param mappedNodesTotal
	 */
	public void setMappedNodesTotal(float mappedNodesTotal) {
		this.mappedNodesTotal = mappedNodesTotal;
	}
	
	
	
	public HashMap<String, NodesAndValues> getMapping() {
		return mapping;
	}

	public void setMapping(HashMap<String, NodesAndValues> mapping) {
		this.mapping = mapping;
	}

	@Override
	public String toString(){
		String temp = "SBV: " + SubNodes + " subTotal: " + mappedNodesTotal + "\n" + "SEV: " + IADEdges + " SNV: " + IADNodes;
		
		temp = temp + "\n" + "Mapping: " + mappingString();
		
		
		return temp;
	}
	
	
	private String mappingString(){
		String tempString = "";
		
		Iterator<NodesAndValues> iterator = mapping.values().iterator();
		while(iterator.hasNext()){
			NodesAndValues navTemp = iterator.next();
			tempString = tempString + "\n" + navTemp.getNode1ID() + " - " + navTemp.getNode2ID();
		}
		
		return tempString;
	}
}
